<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="orderList">
      <el-table-column label="使用明细" align="center">
        <template slot-scope="scope">
          <p>{{ typesMap[scope.row.serviceId] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="订单标识" align="center" prop="orderSnId" />
      <el-table-column label="使用金额" align="center" prop="actualPaidPrice" />
      <el-table-column label="使用时间" align="center">
        <template slot-scope="scope">
          <p>{{ timestampToDate(scope.row.createTime) }}</p>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { ASSOC_SEARCH_BY_USER } from '@/constant/const'
import { timestampToDate } from '@/utils/time'
import { PROPS_ID, WATCH_ID } from '@/constant/const'

import { listRechargeByUser } from '@/api/order/order'
import { listType } from '@/api/service-manager/manager'
export default {
  name: 'Order',

  props: {
    ...PROPS_ID
  },
  watch: {
    ...WATCH_ID
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      typesMap: {},
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: '',

      // 查询参数
      queryParams: { ...ASSOC_SEARCH_BY_USER }
    }
  },
  created() {
    listType(this).then(res => {

      console.log("this.typesMap", res);
      for (const iterator of res) {
        this.typesMap[iterator.id] = iterator.typeName;
      }

    });
  },
  mounted() {
    this.getList(null)
  },
  methods: {
    timestampToDate,

    /** 查询订单列表 */
    getList(dateRange) {
      this.loading = true

      if (dateRange) {
        this.queryParams.startTime = dateRange[0] ? new Date(dateRange[0]).getTime() / 1000 : '';
        this.queryParams.endTime = dateRange[1] ? new Date(dateRange[1]).getTime() / 1000 : '';
      }
      listRechargeByUser(this.queryParams).then((response) => {
        this.orderList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>

<style></style>
